package com.bishe.bishe.dao.mapper;

import com.bishe.bishe.pojo.Species;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
public interface SpeciesMapper<Repository> extends Mapper<Species> {

    @Results({
            @Result(property = "speciesId",column = "species_id"),
            @Result(property = "speciesName",column = "species_name"),
            @Result(property = "speciesPrice",column = "species_price"),
            @Result(property = "speciesImg",column = "species_img"),
            @Result(property = "speciesIntroduce",column = "species_introduce"),
            @Result(property = "types",column = "type_species",one = @One(select = "com.bishe.bishe.dao.mapper.TypesMapper.findByTypes")),
            @Result(property = "speciesTotal",column = "species_total"),
            @Result(property = "unit",column = "species_unit_name",one = @One(select = "com.bishe.bishe.dao.mapper.UnitMapper.findByName")),
            @Result(property = "speciesState",column = "species_state"),
    })
    @Select("select * from species where species_state like '%架%'")
    List<Species> findall();



    @Results({
            @Result(property = "speciesId",column = "species_id"),
            @Result(property = "speciesName",column = "species_name"),
            @Result(property = "speciesPrice",column = "species_price"),
            @Result(property = "speciesImg",column = "species_img"),
            @Result(property = "speciesIntroduce",column = "species_introduce"),
            @Result(property = "types",column = "type_species",one = @One(select = "com.bishe.bishe.dao.mapper.TypesMapper.findByTypes")),
            @Result(property = "speciesTotal",column = "species_total"),
            @Result(property = "unit",column = "species_unit_name",one = @One(select = "com.bishe.bishe.dao.mapper.UnitMapper.findByName")),
            @Result(property = "speciesState",column = "species_state"),
    })
    @Select("select * from species where species_name like '%${speciesName}%'")
    List<Species> findByName(@Param("speciesName") String speciesName);

    @Results({
            @Result(property = "speciesId",column = "species_id"),
            @Result(property = "speciesName",column = "species_name"),
            @Result(property = "speciesPrice",column = "species_price"),
            @Result(property = "speciesImg",column = "species_img"),
            @Result(property = "speciesIntroduce",column = "species_introduce"),
            @Result(property = "types",column = "type_species",one = @One(select = "com.bishe.bishe.dao.mapper.TypesMapper.findByTypes")),
            @Result(property = "speciesTotal",column = "species_total"),
            @Result(property = "unit",column = "species_unit_name",one = @One(select = "com.bishe.bishe.dao.mapper.UnitMapper.findByName")),
            @Result(property = "speciesState",column = "species_state"),
    })
    @Select("select * from species where species_name like '${speciesName}'")
    List<Species> findByNames(@Param("speciesName") String speciesName);

    @Results({
            @Result(property = "speciesId",column = "species_id"),
            @Result(property = "speciesName",column = "species_name"),
            @Result(property = "speciesPrice",column = "species_price"),
            @Result(property = "speciesImg",column = "species_img"),
            @Result(property = "speciesIntroduce",column = "species_introduce"),
            @Result(property = "types",column = "type_species",one = @One(select = "com.bishe.bishe.dao.mapper.TypesMapper.findByTypes")),
            @Result(property = "speciesTotal",column = "species_total"),
            @Result(property = "unit",column = "species_unit_name",one = @One(select = "com.bishe.bishe.dao.mapper.UnitMapper.findByName")),
            @Result(property = "speciesState",column = "species_state"),
    })
    @Select("select * from species where species_id=#{speciesId}")
    Species finddetailById( Integer speciesId);

    @Update("update species set species_img=#{species.speciesImg} where species_id=#{species.speciesId}")
    int updateImg(@Param("species") Species species);


    @Update("update species set species_state=#{speciesState} where species_id=#{speciesId}")
    int updatestate(@Param("speciesId") Integer speciesId,@Param("speciesState")String speciesState);

    @Insert("insert into species(species_id,species_name,species_img,species_price,species_introduce,type_species,species_total,species_unit_name,species_state) value(null,#{species.speciesName},#{species.speciesImg},#{species.speciesPrice},#{species.speciesIntroduce},#{species.types.typeName},#{species.speciesTotal},#{species.unit.unitName},#{species.speciesState})")
    int insert(@Param("species") Species species);

    @Update("update species set species_name=#{speciesName},species_price=#{speciesPrice},species_introduce=#{speciesIntroduce},type_species=#{typeName},species_total=#{speciesTotal},species_unit_name=#{unitName},species_state=#{speciesState} where species_id=#{speciesId}")
    int update(@Param("speciesName") String speciesName,@Param("speciesPrice") Double speciesPrice,@Param("speciesIntroduce") String speciesIntroduce,@Param("typeName") String typeName,@Param("speciesTotal") Integer speciesTotal,@Param("unitName") String unitName,@Param("speciesState") String speciesState,@Param("speciesId") Integer speciesId);

    @Update("update species set species_img=#{speciesImg},species_name=#{speciesName},species_price=#{speciesPrice},species_introduce=#{speciesIntroduce},type_species=#{types.typeName},species_total=#{speciesTotal},species_unit_name=#{unit.unitName},species_state=#{speciesState} where species_id=#{speciesId}")
    int updateImg2(Species species);

    @Select("select species_img from species ")
    List<String> listImg();
}
